<script>
import { mapState, mapGetters, mapMutations } from 'vuex';
import * as types from '@/store/types';
import * as helps from '@/utils/helps';

/*
 * 模块基类
 */
export default {
  name: 'BaseModule',
  computed: {
    ...mapState({
      modules: state => state.statisticApp.modules,
      leftModules: state => state.statisticApp.leftModules,
      bottomModules: state => state.statisticApp.bottomModules,
    }),
    ...mapGetters(['activedLeftModule', 'activedBottomModule']),
  },
  methods: {
    ...mapMutations({
      toggleLeftModule: types.TOGGLE_LEFT_MODULE,
      setLeftPanelState: types.SET_LEFT_PANEL_STATE,
      addBottomModule: types.ADD_BOTTOM_MODULE,
      removeBottomModule: types.REMOVE_BOTTOM_MODULE,
      activeBottomModule: types.ACTIVE_BOTTOM_MODULE,
      setBottomPanelState: types.SET_BOTTOM_PANEL_STATE,
      setModuleOptions: types.SET_MODULE_OPTIONS,
    }),
    /*
     * 获取模块信息
     * @param {String} name 模块名称
     */
    getModuleInfo(name) {
      let item = this.leftModules.find(p => p.name == name);
      if (!item) {
        item = this.bottomModules.find(p => p.name == name);
      }
      return helps.deepCopy(item);
    },
    /*
     * 增加底部模块并激活模块
     * @param {String} type 模块类型
     * @param {String} id 模块id
     * @param {String} title 模块标题
     * @param {Number} order 插入序号
     * @param {Object} options 控件创建选项
     */
    addBottomModuleEx({ type, id, title, order, options }) {
      this.addBottomModule({ type, id, title, order, options });
      this.activeBottomModule(id);
    },
  },
};
</script>

<template>
  <div>

  </div>
</template>

<style lang="less">
</style>
